﻿using System;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Tanmia.Basis.Prism;
using Tanmia.Basis.ViewInterface;
using Tanmia.Basis.ViewModel;
using Tanmia.Warehouse.Core;
using Tanmia.Warehouse.Domain;

namespace Tanmia.Warehouse.Presentation.Scenarios
{
    [ViewInfo("استعراض المميزات", Constants.RegionMain, Views.DiscriminatorBrowser)]
    public class DiscriminatorBrowserViewModel : BrowserViewModel<Discriminator>
    {
        public ICommand ShowEditorCommand { get; private set; }
        public ICommand AddNewCommand { get; private set; }

        public DiscriminatorBrowserViewModel(IShellView shellView, IRegionManager regionManager, IEventAggregator eventAggregator, IMessageService messageService, DiscriminatorDomain discriminatorObj)
            : base(shellView, regionManager, eventAggregator, messageService, discriminatorObj)
        {
            EntityName = "Discriminator";

            ShowEditorCommand = new DelegateCommand(OnShowEditor, OnCanDelete);
            AddNewCommand = new DelegateCommand(OnAddNew, OnCanDelete);
        }

        protected virtual void OnShowEditor()
        {
            RegionManager.NavigateToEditor(Views.DiscriminatorEditor, CurrentEntity);
        }

        protected virtual void OnAddNew()
        {
            RegionManager.RequestNavigate(Constants.RegionEditor, Views.DiscriminatorEditor, Constants.ParentEntityParam, CurrentEntity);
        }

        protected override void CurrentChangedHandler(object sender, EventArgs e)
        {
            base.CurrentChangedHandler(sender, e);
            ((DelegateCommand)ShowEditorCommand).RaiseCanExecuteChanged();
            ((DelegateCommand)AddNewCommand).RaiseCanExecuteChanged();
        }
    }
}
